package com.gjt.URI_URL.authority;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created with Intel IDEA.
 *
 * @Auther: gjt
 * @Date: 2024/3/23 15:46
 */
public class SecureSourceViewer {
    public static void main(String[] args) throws MalformedURLException {
        Authenticator.setDefault(new DialogAuthenticator());
        for (String arg : args) {
            try{
                URL url = new URL(arg);
                try(BufferedReader buf= new BufferedReader(new InputStreamReader(url.openStream()))){
                    int c;
                    char[] list = new char[1024];
                    while((c = buf.read(list)) != -1){
                        System.out.println(new String(list));
                    }
                }catch (IOException e){
                    e.printStackTrace();
                }
            }catch (MalformedURLException e){
                e.printStackTrace();
            }
        }

        // 由于我们使用awt 必须显式退出
        System.exit(0);
    }
}
